/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.elcom.emocbc.cbcgateway.smscbresponse;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

/**
 *
 * @author GiangLT
 */
public class SendMessageResponseHandler extends DefaultHandler {

    private SendMessageResponse sendMessageResponse = new SendMessageResponse();
    private String temp;

    @Override
    public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
        super.startElement(uri, localName, qName, attributes);

    }

    @Override
    public void endElement(String uri, String localName, String qName) throws SAXException {
        if (qName.equals("messageId")) {
            sendMessageResponse.setMessageId(temp);
        }
        if (qName.equals("status")) {
            try {
                sendMessageResponse.setStatus(Integer.valueOf(temp));
            } catch (NumberFormatException numberFormatException) {
                sendMessageResponse.setRequestResult(temp);
            }
        }
        if (qName.equals("statusDescription")) {
            sendMessageResponse.setStatusDescription(temp);
        }
    }

    @Override
    public void characters(char[] ch, int start, int length) throws SAXException {
        temp = new String(ch, start, length);
    }

    public SendMessageResponse getSendMessageResponse() {
        return sendMessageResponse;
    }
}
